import { Component } from 'react'
import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import './index.scss'
import global from '../../global';
import { Textarea, Button, Map, Swiper, SwiperItem, Picker, Input, Image } from '@tarojs/components'
import Request from "../../api";
import Event from "../../event";
export default class Index extends Component {

  constructor(props) {
    super(props);
    this.state = {
      familyMembers: []
    };
    this.loadFamilyMembers = this.loadFamilyMembers.bind(this);
  }

  componentWillMount () {
    this.loadFamilyMembers();
  }

  componentWillUnmount () { }

  componentDidHide () { }

  async loadFamilyMembers() {
    try {
      let res = await Request.get('/wx/getFamilyMembers?userId=' + global.userInfo.userId + '&villageId=' + global.currentBindingVillage.villageId);
      if (res.data.code !== 200) {
        Taro.showToast({
          title: res.data.msg
        })
        throw new Error();
      }
      console.log(res)
      this.setState({
        familyMembers: res.data.data
      })
    } catch (e) {
      console.log('加载车辆数据失败')
    }
  }

  render () {

    let  {familyMembers} = this.state;
    return (
      <View className='family_list'>
        {
          familyMembers.length !== 0 ? familyMembers.map(item => {
            return (
              <View className='family_item'>
                <Image src={item.avatar}/>
                <View className={'info'}>
                  <Text>{item.realName}{
                    Number(item.userId) === global.userInfo.userId && <Text className='self_info'>本人</Text>
                  }</Text>
                  <Text>{item.villageName}-{item.buildingName}-{item.unitName}-{item.houseName}</Text>
                </View>
                <View className={'status'}>
                  <Text style={{color: item.status === '2' ? 'green' : 'yellow'}}>{item.status === '2' ? '认证通过' : '认证中'}</Text>
                  <Text>{item.updateTime}</Text>
                </View>
              </View>
            );
          })
            :
            <View className='message_container'>
              暂无家庭成员
            </View>
        }
      </View>
    )
  }
}
